package org.zdc.pivot.wtk;
import nme.display.Sprite;
import nme.display.Graphics;
import org.zdc.pivot.wtk.Cursor;
import org.zdc.pivot.error.IllegalArgumentException;
import org.zdc.pivot.wtk.effects.IDecorator;

class Component extends Sprite, implements IConstrainedVisual
{
	//皮肤
	private var skin:ISkin = null;
	
	//期望宽高
	private var preferredWidth:Int = -1;
	private var preferredHeight:Int = -1;
	
	//Bounds期望尺寸
	private var minWidth:Int = 0;
	private var maxWidth:Int = Math.POSITIVE_INFINITY;
	private var minHeight:Int = 0;
	private var maxHeight:Int = Math.POSITIVE_INFINITY;
	
	//期望尺寸
	private var preferredSize:Dimensions = null;
	
	//当前尺寸的基线
	private var baseline:Int = -1;
	
	//父容器
	private var parent:Container;
	
	//组件布局有效状态
	private var valid:Bool = false;
	
	//组件的位置
	private var x:Int = 0;
	private var y:Int = 0;
	
	//组件可见性
	private var visible:Bool = false;
	
	//组件装饰器
	private var decorators = new Array<IDecorator>();
	private var decoratorsSeq:DecoratorSequence = {
		private var decs:Array<IDecorator> = [];
		
		function add(dec:IDecorator):Int {
			var index:Int = getLength();
			insert(dec, index);
		}
		
		function insert(dec:IDecorator, index:Int):Int {
			if (dec == null) {
				throw new IllegalArgumentException("decorator is null");
			}
			//重绘之前的装饰区域
			if (parent) {
				parent.repaint();
			}
			decs.insert(index, dec);
		}
		
		function update(index:Int, dec:IDecorator):IDecorator;
		function remove(dec:IDecorator, ?count:Int):Int;
		function removeAll():Array<IDecorator>;
		function get(index:Int):IDecorator;
		function indexOf(dec:IDecorator):Int;
		function getLength():Int;  
	}
	
	//组件可用性
	private var enabled:Bool = true;
	
	//鼠标位置
	private var mouseLocation:Point = null;
	
	//组件的光标
	private var cursor:Cursor = null;
	
	//提示
	private var tooltipText:String = null;
	private var tooltipDelay:Int = 1000;
	private var triggerTooltipCallBack:Dynamic;
	
	//拖放源和对象
	private var dragSource:IDragSource = null;
	private var dropTarget:IDropTarget = null;
	
	//菜单处理器
	private var menuHandler:IMenuHandler = null;
	
	//组件名称
	private var name:String = null;
	
	//组件样式
	private var styles = null;
	private var styleDictionary:StrDictStrItr = {
		
	};
	
	//用户数据
	private var userData:Hash<Dynamic> = new Hash<Dynamic>();
	private var userDataDictionary:StrDictStrItr = {
		
	};
	
	//容器属性
	private var attributes:Hash<Dynamic> = new Hash<Dynamic>();
	
	//组件自动Id
	private var automationID:String;
	
	//侦听器列表
	private var componentListeners:Array<Dynamic> = new Array<Dynamic>();
	private var componentStateListeners:Array<Dynamic> = new Array<Dynamic>();
	private var componentDecoratorListeners:Array<Dynamic> = new Array<Dynamic>();
	private var componentStyleListeners:Array<Dynamic> = new Array<Dynamic>();
	private var componentMouseListeners:Array<Dynamic> = new Array<Dynamic>();
	private var componentMouseButtonListeners:Array<Dynamic> = new Array<Dynamic>();
	private var componentMouseWheelListeners:Array<Dynamic> = new Array<Dynamic>();
	private var componentKeyListeners:Array<Dynamic> = new Array<Dynamic>();
	private var componentTooltipListeners:Array<Dynamic> = new Array<Dynamic>();
	private var componentDataListeners:Array<Dynamic> = new Array<Dynamic>();
	
	//当前拥有焦点的组件
	private static var focusedComponent:Component = null;
	
	//类型和名称样式
	private static var typedStyles = { };
	private static var namedStyles = { };
	
	//类事件侦听器
	private static var componentClassListeners:Array<Dynamic> = new Array<Dynamic>();
	
	
	public function getAutomationID():String {
		
	}
	
	public function setAutomationID(autoID:String):Void {
		
	}
	
	public function getSkin():ISkin {
		
	}
	
	public function setSkin(skin:ISkin):Void {
		
	}
	
	public function installSkin(compClass:Class<Component>):Void {
	}
	
	
}

typedef StrDictStrItr = {
	function get(key:String):Dynamic; 
	function put(key:String, value:Dynamic):Dynamic;
	function remove(key:String):Dynamic;
	function containsKey(key:String):Bool;
	function isReadOnly(key:String):Bool;
	function getType(key:String):Dynamic;
	function iterator():Iterator<String>;
};

typedef DecoratorSequence = {
	private var decs:Array<IDecorator>;
	function add(dec:IDecorator):Int;
	function insert(dec:IDecorator, index:Int):Int;
	function update(index:Int, dec:IDecorator):IDecorator;
	function remove(dec:IDecorator, ?count:Int):Int;
	function removeAll():Array<IDecorator>;
	function get(index:Int):IDecorator;
	function indexOf(dec:IDecorator):Int;
	function getLength():Int;
};

typedef ComponentListenerList = {
	
};
